<?php
use yii\helpers\Html;
use common\components\helpers\Fun;
?>
<div class="yx-praise-box yx-radius2">
    <div class="yx-search-class" data-url="<?=Fun::url(['role/setaccess', 'name' => $role->name])?>">
        <a href="<?=Fun::url('role/index')?>" class="yx-back-list yx-radius5">返回上级列表</a>
    </div>

    <?php if(!empty($parent)){?>
        <div class="yx-class-box yx-pb250">
            <ul class="pub nav nav-tabs yx-nav-tabs1" id="myTab">
                <?php foreach($parent as $k=>$v){?>
                    <li class="yx-width112"><a class="nav_button" id="nav_button_<?=$v['id']?>" data-id="<?=$v['id']?>" data-toggle="tab"><?=$v['name']?></a></li>
                <?php }?>
            </ul>
            <div class="tab-content">
                <?php foreach($array as $key=>$val){
                    if($key==3){?>
                        <div class="tab-pane active" id="table_<?=$key?>">
                    <?php }else{?>
                         <div class="tab-pane" id="table_<?=$key?>">
                    <?php }?>
                        <table  class="example-advanced table yx-table4 table-bordered yx-table1">
                            <thead>
                            <tr class="yx-bgdff3fe">
                                <th>序号</th>
                                <th>编号</th>
                                <th>菜单名称</th>
                                <th class="yx-br">开关</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?=$val?>
                            </tbody>
                        </table>
                        <div class="yx-floatr">
                            <?=Html::submitButton('保存',['class'=>"btn yx-save yx-radius50"])?>
                        </div>
                    </div>
                <?php }?>
            </div>
        </div>
    <?php }?>
    </div>

<?php
$js=<<<JS
  //树表格
    $(".example-advanced").treetable({expandable: true,clickableNodeNames:true,indent:19});
    $(".active .example-advanced").treetable("expandAll");

    // Highlight selected row
    $(".example-advanced").on('click','tbody tr',function() {
        $(this).addClass("zx_selected").siblings().removeClass("zx_selected");
    });
    //开关
    // $('input[type=checkbox]').onoff();

    $('.yx-save').click(function(){
        var checked='';
        $('.yx-switch:checked').each(function () {
            (checked.length == 0) ? checked += $(this).val() : checked += ',' + $(this).val();
        });
        var url = $('.yx-search-class').data('url');
        $.post(url, {ajax: 'set',checked:checked},function (data) {
            alert(data);
        }, 'json');
    });
    $('.nav-tabs li:first-child').addClass('active');
    $('.nav_button').click(function(){
        var id=$(this).data('id');
        $(".tab-pane").removeClass('active');
        $('#table_'+id).addClass('active');
        $('.nav_button').removeClass('mytable-chose');
        $('#nav_button_'+id).addClass('mytable-chose');
        $(".active .example-advanced").treetable("expandAll");

    })
JS;
$this->registerJs($js);

?>
